package com.ljt.controller;

import com.ljt.admin.feign.RemoteTokenService;
import com.ljt.common.constant.SecurityConstants;
import com.ljt.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author administrator
 * @date 2019/07/25
 * @date 2018/9/4
 * getTokenPage 管理
 */
@Api(value = "Token管理", tags = {"Token管理"})
@RestController
@AllArgsConstructor
@RequestMapping("/token")
public class TokenController {
	private final RemoteTokenService remoteTokenService;

	/**
	 * 分页token 信息
	 *
	 * @param params 参数集
	 * @return token集合
	 */
	@ApiOperation(value = "分页查询角色信息", notes = "作者：administrator")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType="query", name = "current", value = "当前页码", required = true, dataType = "Integer"),
			@ApiImplicitParam(paramType="query", name = "size", value = "条数", required = true, dataType = "Integer")
	})
	@GetMapping("/page")
	public BaseResult token(@RequestParam Map<String, Object> params) {
		return remoteTokenService.getTokenPage(params, SecurityConstants.FROM_IN);
	}

	/**
	 * 删除
	 *
	 * @param id ID
	 * @return success/false
	 */
	@ApiOperation(value = "删除token", notes = "作者：administrator")
	@ApiImplicitParam(paramType="path", name = "id", value = "对象id", required = true, dataType = "String")
	@DeleteMapping("/{id}")
	@PreAuthorize("@pms.hasPermission('sys_token_del')")
	public BaseResult<Boolean> delete(@PathVariable String id) {
		return remoteTokenService.removeToken(id, SecurityConstants.FROM_IN);
	}
}
